//
//  YXClientView.m
//  跑跑快销
//
//  Created by 杨潇 on 14-4-28.
//  Copyright (c) 2014年 ylife. All rights reserved.
//
#define ViewHeight                      [UIScreen mainScreen].bounds.size.height
#define searchBarH                      44
#import "YXClientView.h"

@implementation YXClientView
@synthesize clientTableView, searchField, recordImg, blackBtn, showSV;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self createUI];
    }
    return self;
}

#pragma mark - CreateUI

- (void)createUI
{
    
    int navBarY,navBarH;
    
    if (ISDEVICE7) {
        navBarY = 0;
        navBarH = 64;
    }else{
        navBarY = 20;
        navBarH = 44;
    }
    _navBarH = navBarH;
    _navBarY = navBarY;
    
    clientTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, ViewHeight - _navBarH)];
    clientTableView.showsVerticalScrollIndicator = NO;
    clientTableView.backgroundColor = [UIColor clearColor];
    [self addSubview:clientTableView];
}

- (void)showSearchView
{
    showSV = YES;
    if (blackBtn) {
        blackBtn.hidden = NO;
    } else {
        [self createSearchView];
    }
}

- (void)hiddenSearchView
{
    showSV = NO;
    blackBtn.hidden = YES;
    [searchField resignFirstResponder];
}

- (void)createSearchView
{
    //加黑色
    blackBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, _navBarY+20, 320, self.window.frame.size.height-_navBarY)];
    blackBtn.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.35];
    [blackBtn addTarget:self action:@selector(hiddenSearchView) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:blackBtn];
    
    // 搜索框
    searchField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, searchBarH)];
    searchField.borderStyle = UITextBorderStyleRoundedRect;
    searchField.backgroundColor = [UIColor whiteColor];
    [blackBtn addSubview:searchField];
    
    //设置文本左边图片
    UIImageView *image0 =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pass.png"]];
    image0.frame = CGRectMake(0, 0, searchField.frame.size.height, searchField.frame.size.height);
    searchField.leftView = image0;
    searchField.leftViewMode = UITextFieldViewModeAlways;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
